#!/usr/bin/env python
# -*- coding:utf-8 -*-

#1. 内建函数__import__()
# 主程序模块test.py
"""
if __name__=="__main__":
    mod = __import__('test1')
    cls = getattr(mod,'A')
    cls().showme()
"""

# 2. importlib动态导入
# 主程序模块test.py,插件化编程的核心代码:
import importlib

def plugin_load(plugin_name:str,sep=":"):
    m,_,c = plugin_name.partition(sep)
    mod = importlib.import_module(m)
    cls = getattr(mod,c)  
    return cls()

if __name__=='__main__':
    # 装载插件
    a = plugin_load('test1:A')
    a.showme()
